<?php

class Utilities
{
	//seed for random generator
	public function make_seed()
	{
    	list($usec, $sec) = explode(' ', microtime());
  		return (float) $sec + ((float) $usec * 100000); 
	} 		
	
	// make the token 
	public function make_token($token_len) 
	{ 
	  	//seed the random generator 
	    mt_srand(utilities::make_seed()); 
	  	//create token
	    $token = ""; 
	    for ($loop = 0; $loop < $token_len; $loop++) 
	    { 
	        switch(mt_rand(0, 2))
	        { 
	            case 0: $token .= mt_rand(0, 9);            break; // Number (0-9) 
	            case 1: $token .= chr(mt_rand(97, 122));    break; // Alpha Lower (a-z) 
	            case 2: $token .= chr(mt_rand(65, 90));    break; // Alpha Upper (A-Z) 
	        }
	    }
	  return $token;
	}
	
	public function smtpSendMailAction($Receiver_Email,$mail_Message,$mail_Type,$mail_Subject)
	{
		//Create SMTP connection Object
		$configInfo = array('auth' => 'login',
							'ssl' => 'tls',
							'username' => 'medadvisor111@gmail.com',
							'password' => 'doktori123',
							'port' => 587);
		$smtpHost = new Zend_Mail_Transport_Smtp('smtp.gmail.com',$configInfo);
		Zend_Mail::setDefaultTransport($smtpHost);

		//Create Zend_Mail object.
		$MailObj = new Zend_Mail();
		
		//Initialize parameters.
		
		$fromEmail = "medadvisor111@gmail.com";
		$fromFullName = "Med-Advisor";
		$to = $Receiver_Email;
		$subject = $mail_Subject;
		$emailMessage = $mail_Message;
		
		$MailObj->setBodyText($emailMessage);
		$MailObj->setFrom($fromEmail, $fromFullName);
		$MailObj->addTo($to);
		$MailObj->setSubject($subject);
		
		//Send Email using transport protocol.
		try{
			$MailObj->send($smtpHost);
			echo "Email sent successfully";
			return true;
		}catch(Zend_Mail_Exception $e){
			//Your error message here.
			echo $e->getMessage();
			return false;
		}
		//Suppress the view.
		//$this->_helper->viewRenderer->setNoRender();
	}
	
	public function formMoodHome($text,$mood,$user_id){
		try{
			$userOB = new Application_Model_DbTable_Users();
			$username = $userOB->getUser($user_id);          //zemi go objektot User za prijatelot cij status se obrabotuva
			
			switch ($mood) {								//proveri kakov mood zapishal
	    		case 1:
	        		$m = "Bad"; break;
	    		case 2:
	        		$m = "Ok"; break;
	    		case 3:
	        		$m = "Good"; break;
			}
			
			$line = $username['Username'] /*$user_id*/ . " is feeling " . $m . ", because: " .$text; //tekstot koj ke se prikaze kako status
			return $line;
		}		
		catch (Zend_Exception $e){
			echo "Error message: " . $e->getMessage() . "\n";
			return null;			  
		}
	}
	
	public function formMoodProfile($text,$mood){
		try{			
			switch ($mood) {								//proveri kakov mood zapishal
	    		case 1:
	        		$m = "Bad"; break;
	    		case 2:
	        		$m = "Ok"; break;
	    		case 3:
	        		$m = "Good"; break;
			}
			
			$line = "I am feeling " . $m . ", because: " .$text; //tekstot koj ke se prikaze kako status
			return $line;
		}		
		catch (Zend_Exception $e){
			echo "Error message: " . $e->getMessage() . "\n";
			return null;			  
		}
	}
}